﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace MvcShop.MVC.Services
{
    public class BaseControllerService:IBaseControllerService
    {
        private string shopName;
        private string emailAddress;
        private string copyright;
        private string phoneNumber;

        public string GoogleTrackingCode { get; set; }
        public string PageDescription { get; set; }

        public string EmailAddress
        {
            get
            {
                if (string.IsNullOrEmpty(emailAddress)) return string.Empty;
                return emailAddress;
            }
            set { emailAddress = value; }
        }

        public string ShopName
        {
            get
            {
                if (string.IsNullOrEmpty(shopName))
                {
                    return "SouthShop";
                }
                return shopName;
            }
            set { shopName = value; }
        }

        public virtual string SiteUrl
        {
            get
            {

                Uri url = CurrentHttpContext.Request.Url;
                string relativePath = CurrentHttpContext.Request.ApplicationPath;

                if (!relativePath.EndsWith("/"))
                {
                    relativePath += "/";
                }

                string port = (url.Port == 80) ? "" : ":{0}".With(url.Port.ToString());

                return "{0}://{1}{2}{3}".With(url.Scheme, url.Host, port, relativePath);
            }
        }

        public virtual HttpContext CurrentHttpContext
        {
            get
            {
                if (HttpContext.Current == null)
                {
                    throw new ApplicationException("There is no current HttpContext");
                }
                return HttpContext.Current;
            }
        }

        public virtual string Copyright
        {
            get
            {
                if (string.IsNullOrEmpty(copyright)) return "Copyright©2009-2016  yeaszi  版权所有";
                return copyright;
            }
            set { copyright = value; }
        }

        public string PhoneNumber
        {
            get
            {
                if (string.IsNullOrEmpty(phoneNumber)) return "";
                return phoneNumber;
            }
            set { phoneNumber = value; }
        }

        public string RecordNumber { get; set; }

        public string IPCNumber { get; set; }
    }
}
